hysop.numerics.interpolation.polynomial module

class hysop.numerics.interpolation.polynomial.PolynomialInterpolator(dim, deg, fd, approximative=False, verbose=False)[source]

Bases: object

Create a PolynomialInterpolator.

Parameters:
  • dim (int) – Number of dimensions to interpolate.

  • deg (int or tuple of ints) – Polynomial degree (1=linear, 3=cubic, 5=quintic, 7=septic, …) Degree should be odd on each axis.

  • fd (int or tuple of ints) – Order of centered finite differences used to compute derivatives in each direction. Will affect the number of ghosts of the method. Should be even because this interpolator only use centered dinite differences.

  • approximative (bool) – Use np.float64 instead of exact fractions to compute weights.

  • verbose (bool) – Enable or disabled verbosity, default to False.

dim

Number of dimensions to interpolate.

Type:

int

deg

Polynomial degree (1=linear, 3=cubic, 5=quintic, 7=septic, …) Degree should be odd: deg=2k+1

Type:

tuple of ints

fd

Order of centered finite differences stencils used to compute derivatives for each direction.

Type:

tuple of ints

p

Corresponds to deg+1. The total number of polynomial coefficients corresponds to P=p0*p1*…*p(dim-1).

Type:

tuple of ints

P

The total number of polynomial coefficients P=p0*p1*…*p(dim-1)

Type:

int

k

Max derivative order required to compute the polynomial interpolator coefficients in each direction. Also the regularity of the resulting interpolant. Corresponds to (deg-1)/2.

Type:

tuple of ints

ghosts

Return the number of ghosts required by the interpolator on each axis. Corresponds to (k>0)*[fd//2 - 1 + (k+1)//2]

deg k (k+1)/2 | FDC2 FDC4 FDC6

linear: 1 0 0 | 0 0 0 cubic: 3 1 1 | 1 2 3 quintic: 5 2 1 | 1 2 3 septic: 7 3 2 | 2 3 4 nonic: 9 4 2 | 2 3 4

Type:

tuple of ints

n

Corresponds to 2*(ghosts+1), the number of required nodes to generate the polynomial coefficients (in each direction). In total we have N=n0*n1*…*n(dim-1) input nodes.

G1 G1

<-> <->

X X X X X P P X X P P X X X X X <—–>

n1

Type:

tuple of ints

N

Total number of input nodes N=n0*n1*…*n(dim-1).

Type:

int

M
Grid values to polynomial coefficient matrix:
M.dot(F.ravel()) will give C.ravel(), coefficients of P(x0,x1,…)

N

<———> X X X X X X ^ |f0| ^ |c0| ^ X X X X X X | |f1| | |c1| |

M = X X X X X X | P F = |f2| | N C = M*F = |c2| | P

X X X X X X | |f3| | |c3| | X X X X X X v |f4| | |c4| v

|f5| v

If approximative is set to True, M will contain np.float64 Else is will contain rationals.

Type:

np.ndarray

See also

PolynomialSubgridInterpolator

Precompute weights for fixed subgrid

interpolation.

classmethod build_interpolator(pi, dim, fd=None, verbose=False, approximative=False)[source]
classmethod cache_file()[source]
generate_subgrid_interpolator(grid_ratio, dtype=None)[source]
interpolate(fvals)[source]

Return the polynomial interpolating input node values

class hysop.numerics.interpolation.polynomial.PolynomialSubgridInterpolator(interpolator, grid_ratio, dtype=None)[source]

Bases: object

Create a PolynomialSubgridInterpolator from a PolynomialInterpolator and a number of subrid points.

Parameters:
  • interpolator (PolynomialInterpolator) – Interpolant used to compute weights.

  • grid_ratio (tuple of int) – Tuple of integers representing the ratio between the coarse and the fine grid.

  • dtype (np.dtype) – Force to cast dtype for all matrices (interpolator.M may contain rationals).

dim

Number of dimensions to interpolate (same as interpolator.dim).

Type:

int

ghosts

Number of required ghosts.

Type:

tuple of int

n

Corresponds to 2*(ghosts+1), the number of required nodes to generate the polynomial coefficients (same as interpolator.n).

Type:

tuple of int

N

Total number of input nodes N including ghosts (same as interpolator.N). N = n0*n1*…*n[dim-1]

Type:

int

s

Corresponds to grid_ratio + 1, number of points of the subgrid in each directions. Example for a grid ratio=(3,3), we have s=(4,4):

O=coarse grid nodes, X=fine grid nodes

Coarse grid: Fine grid:

^ O—–O ^ O X X O | | | | X X X X

1 | | | 4 | X X X X
v O—–O v O X X O
<—–> <—–>

1 4

Type:

tuple of int

S

Represents the number of fine grid points contained in a coarse grid cell. S = s0*s1*…*s[dim-1]

Type:

int

gr

Corresponds to grid_ratio, number of points of the subgrid in each directions, minus one. Example for a grid ratio=(3,3), we have gr=(3,3) and s=(4,4):

O=coarse grid nodes, X=fine grid nodes, -=excluded find grid nodes

Coarse grid: Fine grid:

^ O—–O ^ O X X O ^ | | | gr0 | X X X - | s0

1 | | | v X X X - |
v O—–O O - - O v
<—–> <—>

1 gr1

Type:

tuple of int

GR

Represents the number of fine grid points contained in a coarse grid cell exluding right most points. GR = gr0*gr1*…*gr[dim-1]

Type:

int

W

Pre computed weights to interpolate directly from coarse to fine grid. Let F be the vector of N known coarse grid node values (including required ghosts). Let G be the vector of S unknown fine grid node values.

N

<———> X X X X X X ^ |g0| ^ X X X X X X | |f0| ^ |g1| | X X X X X X | |f1| | |g2| | X X X X X X | |f2| | |g3| |

W = X X X X X X | S F= |f3| | N G = W*F = |g4| | S

X X X X X X | |f4| | |g5| | X X X X X X | |f5| v |g6| | X X X X X X | |g7| | X X X X X X v |g8| v

Will contain the same data type as intepolator.M if dtype is not passed, else W will be computed from user given dtype.

Type:

np.ndarray

Wr

Reduced W that exludes rightmost output points of ndimensional output vector.

Pre computed weights to interpolate directly from coarse to inner fine grid. Let F be the vector of N known coarse grid node values (including required ghosts). Let G be the vector of GR unknown fine inner grid node values (see gr attribute).

N

<———> X X X X X X ^ |g0| ^ X X X X X X | |f0| ^ |g1| | X X X X X X | |f1| | |g2| | X X X X X X | |f2| | |g3| |

Wr = X X X X X X | GR F= |f3| | N G = W*F = |g4| | GR

X X X X X X | |f4| | |g5| | X X X X X X | |f5| v |g6| | X X X X X X | |g7| | X X X X X X v |g8| v

Same data type as W.

Type:

np.ndarray

property Wr
generate_subgrid_restrictor()[source]
class hysop.numerics.interpolation.polynomial.PolynomialSubgridRestrictor(subgrid_interpolator)[source]

Bases: object

Create a PolynomialSubgridRestrictor from a PolynomialSubgridInterpolator.

Parameters:

subgrid_interpolator (PolynomialSubgridInterpolator) – Interpolant used to compute restrictor weights.

g

Corresponds to (n+1)*s

Type:

tuple of int

G

Corresponds to g[0]*g[1]*…g[dim-1]

Type:

int

R

Restrictor weights.

Type:

np.ndarray

origin

Origin of the generated stencil.

Type:

tuple of int

Rr

Restrictor weights excluding leftmost and rightmost points.

Type:

np.ndarray

ghosts

Corresponds to origin - 1, which is also Rr origin.